<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增地址</title>
</head>
<body>
<div id="address1">
  <p>
    收&nbsp;&nbsp;件&nbsp;&nbsp;人:&nbsp;<input type="text" v-model="address.addressee" >
  </p>
  <p>
    联系电话:&nbsp;&nbsp;<input type="text" v-model="address.phone">
  </p>
  <p>
    省&nbsp;&nbsp;市&nbsp;&nbsp;区:&nbsp;<input type="text" v-model="address.area">
  </p>
  <p>
    详细地址:&nbsp;&nbsp;<input type="text" v-model="address.address_detail">
  </p>
  <input type="button" value="新增" @click="add">&nbsp;
  <input type="button" value="返回" @click="returnPages">
</div>
<script src="assets/js/vue.js"></script>
<script src="assets/js/axios.min.js"></script>
<script>
  const ad = new Vue({
    el: "#address1",
    data: {
      address: {
        addressee: "",
        phone: "",
        area: "",
        address_detail: ""
      }
    },
    methods: {
      returnPages() {
        location.href = "invoice-info-manage.html";
      },
      add() {
        let _this = this;
        let formData = new FormData();
        formData.append("addressee", _this.address.addressee);
        formData.append("phone", _this.address.phone);
        formData.append("area", _this.address.area);
        formData.append("address_detail", _this.address.address_detail);
        let flag = _this.address.addressee == "" ||  _this.address.phone == "" || _this.address.area == "" || _this.address.address_detail == "";

        if (flag){
          alert("请输入信息!");
          location.reload();
        }else {
          axios({
            method: "post",
            url: "../admin/addAddress.ad",
            data: formData
          }).then(function (response) {
            let data = response.data;
            alert(data.msg);
            if (data.code == 500) {
              location.href="invoice-info-manage.html";
            }
          })
        }

      }
    }
  })
</script>
</body>
</html>